﻿/**  版本信息模板在安装目录下，可自行修改。
* V_Store.cs
*
* 功 能： N/A
* 类 名： V_Store
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2013/12/10 13:02:28   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace BBPA.DAL
{
	/// <summary>
	/// 数据访问类:V_Store
	/// </summary>
	public partial class V_Store
	{
		public V_Store()
		{}
		#region  BasicMethod



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(BBPA.Model.V_Store model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into V_Store(");
			strSql.Append("id,UserID,Number,Name,ShortName,PicID,Contacts,Tel,Mobile,Province,City,Area,Address,Description,Username,Password,Dateandtime,State,IsLock,PicURL,PicWidth,PicHeight,Rank,BuyDay,Account,ViceAccount,FrozenAccount,MasterAccount,PAFeeEndDate)");
			strSql.Append(" values (");
			strSql.Append("@id,@UserID,@Number,@Name,@ShortName,@PicID,@Contacts,@Tel,@Mobile,@Province,@City,@Area,@Address,@Description,@Username,@Password,@Dateandtime,@State,@IsLock,@PicURL,@PicWidth,@PicHeight,@Rank,@BuyDay,@Account,@ViceAccount,@FrozenAccount,@MasterAccount,@PAFeeEndDate)");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4),
					new SqlParameter("@UserID", SqlDbType.Int,4),
					new SqlParameter("@Number", SqlDbType.NVarChar,50),
					new SqlParameter("@Name", SqlDbType.NVarChar,50),
					new SqlParameter("@ShortName", SqlDbType.NVarChar,50),
					new SqlParameter("@PicID", SqlDbType.Int,4),
					new SqlParameter("@Contacts", SqlDbType.NVarChar,50),
					new SqlParameter("@Tel", SqlDbType.NVarChar,50),
					new SqlParameter("@Mobile", SqlDbType.VarChar,50),
					new SqlParameter("@Province", SqlDbType.NVarChar,50),
					new SqlParameter("@City", SqlDbType.NVarChar,50),
					new SqlParameter("@Area", SqlDbType.NVarChar,50),
					new SqlParameter("@Address", SqlDbType.NVarChar,200),
					new SqlParameter("@Description", SqlDbType.Text),
					new SqlParameter("@Username", SqlDbType.NVarChar,50),
					new SqlParameter("@Password", SqlDbType.VarChar,50),
					new SqlParameter("@Dateandtime", SqlDbType.DateTime),
					new SqlParameter("@State", SqlDbType.TinyInt,1),
					new SqlParameter("@IsLock", SqlDbType.Bit,1),
					new SqlParameter("@PicURL", SqlDbType.NVarChar,100),
					new SqlParameter("@PicWidth", SqlDbType.Int,4),
					new SqlParameter("@PicHeight", SqlDbType.Int,4),
					new SqlParameter("@Rank", SqlDbType.Int,4),
					new SqlParameter("@BuyDay", SqlDbType.TinyInt,1),
					new SqlParameter("@Account", SqlDbType.Money,8),
					new SqlParameter("@ViceAccount", SqlDbType.Money,8),
					new SqlParameter("@FrozenAccount", SqlDbType.Money,8),
					new SqlParameter("@MasterAccount", SqlDbType.Money,8),
					new SqlParameter("@PAFeeEndDate", SqlDbType.Date,3)};
			parameters[0].Value = model.id;
			parameters[1].Value = model.UserID;
			parameters[2].Value = model.Number;
			parameters[3].Value = model.Name;
			parameters[4].Value = model.ShortName;
			parameters[5].Value = model.PicID;
			parameters[6].Value = model.Contacts;
			parameters[7].Value = model.Tel;
			parameters[8].Value = model.Mobile;
			parameters[9].Value = model.Province;
			parameters[10].Value = model.City;
			parameters[11].Value = model.Area;
			parameters[12].Value = model.Address;
			parameters[13].Value = model.Description;
			parameters[14].Value = model.Username;
			parameters[15].Value = model.Password;
			parameters[16].Value = model.Dateandtime;
			parameters[17].Value = model.State;
			parameters[18].Value = model.IsLock;
			parameters[19].Value = model.PicURL;
			parameters[20].Value = model.PicWidth;
			parameters[21].Value = model.PicHeight;
			parameters[22].Value = model.Rank;
			parameters[23].Value = model.BuyDay;
			parameters[24].Value = model.Account;
			parameters[25].Value = model.ViceAccount;
			parameters[26].Value = model.FrozenAccount;
			parameters[27].Value = model.MasterAccount;
			parameters[28].Value = model.PAFeeEndDate;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(BBPA.Model.V_Store model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update V_Store set ");
			strSql.Append("id=@id,");
			strSql.Append("UserID=@UserID,");
			strSql.Append("Number=@Number,");
			strSql.Append("Name=@Name,");
			strSql.Append("ShortName=@ShortName,");
			strSql.Append("PicID=@PicID,");
			strSql.Append("Contacts=@Contacts,");
			strSql.Append("Tel=@Tel,");
			strSql.Append("Mobile=@Mobile,");
			strSql.Append("Province=@Province,");
			strSql.Append("City=@City,");
			strSql.Append("Area=@Area,");
			strSql.Append("Address=@Address,");
			strSql.Append("Description=@Description,");
			strSql.Append("Username=@Username,");
			strSql.Append("Password=@Password,");
			strSql.Append("Dateandtime=@Dateandtime,");
			strSql.Append("State=@State,");
			strSql.Append("IsLock=@IsLock,");
			strSql.Append("PicURL=@PicURL,");
			strSql.Append("PicWidth=@PicWidth,");
			strSql.Append("PicHeight=@PicHeight,");
			strSql.Append("Rank=@Rank,");
			strSql.Append("BuyDay=@BuyDay,");
			strSql.Append("Account=@Account,");
			strSql.Append("ViceAccount=@ViceAccount,");
			strSql.Append("FrozenAccount=@FrozenAccount,");
			strSql.Append("MasterAccount=@MasterAccount,");
			strSql.Append("PAFeeEndDate=@PAFeeEndDate");
			strSql.Append(" where ");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4),
					new SqlParameter("@UserID", SqlDbType.Int,4),
					new SqlParameter("@Number", SqlDbType.NVarChar,50),
					new SqlParameter("@Name", SqlDbType.NVarChar,50),
					new SqlParameter("@ShortName", SqlDbType.NVarChar,50),
					new SqlParameter("@PicID", SqlDbType.Int,4),
					new SqlParameter("@Contacts", SqlDbType.NVarChar,50),
					new SqlParameter("@Tel", SqlDbType.NVarChar,50),
					new SqlParameter("@Mobile", SqlDbType.VarChar,50),
					new SqlParameter("@Province", SqlDbType.NVarChar,50),
					new SqlParameter("@City", SqlDbType.NVarChar,50),
					new SqlParameter("@Area", SqlDbType.NVarChar,50),
					new SqlParameter("@Address", SqlDbType.NVarChar,200),
					new SqlParameter("@Description", SqlDbType.Text),
					new SqlParameter("@Username", SqlDbType.NVarChar,50),
					new SqlParameter("@Password", SqlDbType.VarChar,50),
					new SqlParameter("@Dateandtime", SqlDbType.DateTime),
					new SqlParameter("@State", SqlDbType.TinyInt,1),
					new SqlParameter("@IsLock", SqlDbType.Bit,1),
					new SqlParameter("@PicURL", SqlDbType.NVarChar,100),
					new SqlParameter("@PicWidth", SqlDbType.Int,4),
					new SqlParameter("@PicHeight", SqlDbType.Int,4),
					new SqlParameter("@Rank", SqlDbType.Int,4),
					new SqlParameter("@BuyDay", SqlDbType.TinyInt,1),
					new SqlParameter("@Account", SqlDbType.Money,8),
					new SqlParameter("@ViceAccount", SqlDbType.Money,8),
					new SqlParameter("@FrozenAccount", SqlDbType.Money,8),
					new SqlParameter("@MasterAccount", SqlDbType.Money,8),
					new SqlParameter("@PAFeeEndDate", SqlDbType.Date,3)};
			parameters[0].Value = model.id;
			parameters[1].Value = model.UserID;
			parameters[2].Value = model.Number;
			parameters[3].Value = model.Name;
			parameters[4].Value = model.ShortName;
			parameters[5].Value = model.PicID;
			parameters[6].Value = model.Contacts;
			parameters[7].Value = model.Tel;
			parameters[8].Value = model.Mobile;
			parameters[9].Value = model.Province;
			parameters[10].Value = model.City;
			parameters[11].Value = model.Area;
			parameters[12].Value = model.Address;
			parameters[13].Value = model.Description;
			parameters[14].Value = model.Username;
			parameters[15].Value = model.Password;
			parameters[16].Value = model.Dateandtime;
			parameters[17].Value = model.State;
			parameters[18].Value = model.IsLock;
			parameters[19].Value = model.PicURL;
			parameters[20].Value = model.PicWidth;
			parameters[21].Value = model.PicHeight;
			parameters[22].Value = model.Rank;
			parameters[23].Value = model.BuyDay;
			parameters[24].Value = model.Account;
			parameters[25].Value = model.ViceAccount;
			parameters[26].Value = model.FrozenAccount;
			parameters[27].Value = model.MasterAccount;
			parameters[28].Value = model.PAFeeEndDate;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete()
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from V_Store ");
			strSql.Append(" where ");
			SqlParameter[] parameters = {
			};

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public BBPA.Model.V_Store GetModel()
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 id,UserID,Number,Name,ShortName,PicID,Contacts,Tel,Mobile,Province,City,Area,Address,Description,Username,Password,Dateandtime,State,IsLock,PicURL,PicWidth,PicHeight,Rank,BuyDay,Account,ViceAccount,FrozenAccount,MasterAccount,PAFeeEndDate from V_Store ");
			strSql.Append(" where ");
			SqlParameter[] parameters = {
			};

			BBPA.Model.V_Store model=new BBPA.Model.V_Store();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public BBPA.Model.V_Store DataRowToModel(DataRow row)
		{
			BBPA.Model.V_Store model=new BBPA.Model.V_Store();
			if (row != null)
			{
				if(row["id"]!=null && row["id"].ToString()!="")
				{
					model.id=int.Parse(row["id"].ToString());
				}
				if(row["UserID"]!=null && row["UserID"].ToString()!="")
				{
					model.UserID=int.Parse(row["UserID"].ToString());
				}
				if(row["Number"]!=null)
				{
					model.Number=row["Number"].ToString();
				}
				if(row["Name"]!=null)
				{
					model.Name=row["Name"].ToString();
				}
				if(row["ShortName"]!=null)
				{
					model.ShortName=row["ShortName"].ToString();
				}
				if(row["PicID"]!=null && row["PicID"].ToString()!="")
				{
					model.PicID=int.Parse(row["PicID"].ToString());
				}
				if(row["Contacts"]!=null)
				{
					model.Contacts=row["Contacts"].ToString();
				}
				if(row["Tel"]!=null)
				{
					model.Tel=row["Tel"].ToString();
				}
				if(row["Mobile"]!=null)
				{
					model.Mobile=row["Mobile"].ToString();
				}
				if(row["Province"]!=null)
				{
					model.Province=row["Province"].ToString();
				}
				if(row["City"]!=null)
				{
					model.City=row["City"].ToString();
				}
				if(row["Area"]!=null)
				{
					model.Area=row["Area"].ToString();
				}
				if(row["Address"]!=null)
				{
					model.Address=row["Address"].ToString();
				}
				if(row["Description"]!=null)
				{
					model.Description=row["Description"].ToString();
				}
				if(row["Username"]!=null)
				{
					model.Username=row["Username"].ToString();
				}
				if(row["Password"]!=null)
				{
					model.Password=row["Password"].ToString();
				}
				if(row["Dateandtime"]!=null && row["Dateandtime"].ToString()!="")
				{
					model.Dateandtime=DateTime.Parse(row["Dateandtime"].ToString());
				}
				if(row["State"]!=null && row["State"].ToString()!="")
				{
					model.State=int.Parse(row["State"].ToString());
				}
				if(row["IsLock"]!=null && row["IsLock"].ToString()!="")
				{
					if((row["IsLock"].ToString()=="1")||(row["IsLock"].ToString().ToLower()=="true"))
					{
						model.IsLock=true;
					}
					else
					{
						model.IsLock=false;
					}
				}
				if(row["PicURL"]!=null)
				{
					model.PicURL=row["PicURL"].ToString();
				}
				if(row["PicWidth"]!=null && row["PicWidth"].ToString()!="")
				{
					model.PicWidth=int.Parse(row["PicWidth"].ToString());
				}
				if(row["PicHeight"]!=null && row["PicHeight"].ToString()!="")
				{
					model.PicHeight=int.Parse(row["PicHeight"].ToString());
				}
				if(row["Rank"]!=null && row["Rank"].ToString()!="")
				{
					model.Rank=int.Parse(row["Rank"].ToString());
				}
				if(row["BuyDay"]!=null && row["BuyDay"].ToString()!="")
				{
					model.BuyDay=int.Parse(row["BuyDay"].ToString());
				}
				if(row["Account"]!=null && row["Account"].ToString()!="")
				{
					model.Account=decimal.Parse(row["Account"].ToString());
				}
				if(row["ViceAccount"]!=null && row["ViceAccount"].ToString()!="")
				{
					model.ViceAccount=decimal.Parse(row["ViceAccount"].ToString());
				}
				if(row["FrozenAccount"]!=null && row["FrozenAccount"].ToString()!="")
				{
					model.FrozenAccount=decimal.Parse(row["FrozenAccount"].ToString());
				}
				if(row["MasterAccount"]!=null && row["MasterAccount"].ToString()!="")
				{
					model.MasterAccount=decimal.Parse(row["MasterAccount"].ToString());
				}
				if(row["PAFeeEndDate"]!=null && row["PAFeeEndDate"].ToString()!="")
				{
					model.PAFeeEndDate=DateTime.Parse(row["PAFeeEndDate"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,UserID,Number,Name,ShortName,PicID,Contacts,Tel,Mobile,Province,City,Area,Address,Description,Username,Password,Dateandtime,State,IsLock,PicURL,PicWidth,PicHeight,Rank,BuyDay,Account,ViceAccount,FrozenAccount,MasterAccount,PAFeeEndDate ");
			strSql.Append(" FROM V_Store ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" id,UserID,Number,Name,ShortName,PicID,Contacts,Tel,Mobile,Province,City,Area,Address,Description,Username,Password,Dateandtime,State,IsLock,PicURL,PicWidth,PicHeight,Rank,BuyDay,Account,ViceAccount,FrozenAccount,MasterAccount,PAFeeEndDate ");
			strSql.Append(" FROM V_Store ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM V_Store ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.id desc");
			}
			strSql.Append(")AS Row, T.*  from V_Store T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "V_Store";
			parameters[1].Value = "id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

